package com.jrauto.CarAppBackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jrauto.CarAppBackend.entity.ChatMessage;
import com.jrauto.CarAppBackend.entity.ChatSession;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author huimin
* @description 针对表【chat_message(消息表)】的数据库操作Mapper
* @createDate 2025-09-03 15:29:41
* @Entity generator.domain.ChatMessage
*/
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {

    /**
     * 根据会话ID获取消息列表，支持分页
     * @param sessionId 会话ID
     * @param offset 偏移量
     * @param limit 数量限制
     * @return 消息列表
     */
    @Select("SELECT * FROM chat_message WHERE session_id = #{sessionId} ORDER BY created_at DESC LIMIT #{offset}, #{limit}")
    List<ChatMessage> findMessagesBySessionId(@Param("sessionId") Integer sessionId, @Param("offset") int offset, @Param("limit") int limit);

}




